package com.apexsoft.assets.base.utils;

import com.apexsoft.assets.base.model.Columns;
import io.swagger.annotations.ApiModelProperty;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

public class ColumnUtil {

    public static List<Columns> getColumns(Class cls) {
        List<Columns> columns = new LinkedList<>();
        Field[] fields = cls.getDeclaredFields();

        for (Field field : fields){
            ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
            if(apiModelProperty == null) continue;

            if(apiModelProperty.hidden()) continue;

            Columns col = new Columns();
            col.setCode(field.getName());
            col.setName(apiModelProperty.value());
            col.setType("1");
            columns.add(col);
        }
        return columns;
    }
}
